package com.abcdefg.java_chatroom.api;

import com.abcdefg.java_chatroom.mapper.FriendMapper;
import com.abcdefg.java_chatroom.model.Friend;
import com.abcdefg.java_chatroom.model.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/FriendApi")
public class FriendApi {

    @Autowired
    private FriendMapper friendMapper;

    @GetMapping("/getFriendList")
    public Object getFriendList(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session == null) {
            System.out.println("当前获取不到session对象！！！");
            return new ArrayList<>();
        }
        User user = (User) session.getAttribute("user");
        if(user == null) {
            System.out.println("当前获取不到user对象");
            return new ArrayList<>();
        }
        List<Friend> friendlist=friendMapper.selectFriendList(user.getUserId());
        return friendlist;
    }
}
